---
layout: "default"
title: "ReverseRandomAccessIndex"
description: "Swift documentation for 'ReverseRandomAccessIndex': A wrapper for a RandomAccessIndex that reverses its
direction of traversal."
keywords: "ReverseRandomAccessIndex,struct,swift,documentation,advanced,advanced,distance,predecessor,successor,base,Distance"
root: "/v3.0"
---

<div class="intro-declaration"><code class="language-swift">struct ReverseRandomAccessIndex&lt;Base : RandomAccessIndex&gt;</code></div>

<div class="discussion comment">
    <p>A wrapper for a <code>RandomAccessIndex</code> that reverses its
direction of traversal.</p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">BidirectionalIndex, Comparable, Equatable, ForwardIndex, RandomAccessIndex, ReverseIndexProtocol, Strideable, _Incrementable, _RandomAccessAmbiguity</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>

<tr>
<th id="aliases">Associated Types</th>
<td>
<span id="aliasesmark"></span>
<div class="declaration">
<code class="language-swift">Distance = Base.Distance</code>
</div>
</td>
</tr>


<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_">init(<wbr>_:)</a><div class="comment collapse" id="comment-init_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ base: Base)</code>

    </div></div>
</div>


<h3>Instance Variables</h3>
<div class="declaration" id="var-base_-base">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-base_-base">var base: Base</a><div class="comment collapse" id="comment-var-base_-base"><div class="p">
    <p>The successor position in the underlying (un-reversed)
collection.</p>

<p>If <code>self</code> is <code>advance(c.reverse.startIndex, n)</code>, then:
- <code>self.base</code> is <code>advance(c.endIndex, -n)</code>.
- if <code>n</code> != <code>c.count</code>, then <code>c.reverse[self]</code> is 
  equivalent to <code>[self.base.predecessor()]</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var base: Base { get }</code>

    </div></div>
</div>



<h3>Instance Methods</h3>
<div class="declaration" id="func-advanced-by_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-advanced-by_">func advanced(<wbr>by:)</a>
        
<div class="comment collapse" id="comment-func-advanced-by_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">func advanced(by n: Base.Distance) -&gt; ReverseRandomAccessIndex&lt;Base&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/ReverseRandomAccessIndex/"><code>ReverseRandomAccessIndex</code></a>,    <a href="../../protocol/RandomAccessIndex/"><code>RandomAccessIndex</code></a>,    <a href="../../protocol/ReverseIndexProtocol/"><code>ReverseIndexProtocol</code></a>,    <a href="../../protocol/BidirectionalIndex/"><code>BidirectionalIndex</code></a>,    <a href="../../protocol/_RandomAccessAmbiguity/"><code>_RandomAccessAmbiguity</code></a>,    <a href="../../protocol/ForwardIndex/"><code>ForwardIndex</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-advanced-by_limit_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-advanced-by_limit_">func advanced(<wbr>by:<wbr>limit:)</a>
        
<div class="comment collapse" id="comment-func-advanced-by_limit_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">func advanced(by n: ReverseRandomAccessIndex&lt;Base&gt;.Distance, limit: ReverseRandomAccessIndex&lt;Base&gt;) -&gt; ReverseRandomAccessIndex&lt;Base&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/RandomAccessIndex/"><code>RandomAccessIndex</code></a>,    <a href="../../protocol/ReverseIndexProtocol/"><code>ReverseIndexProtocol</code></a>,    <a href="../../protocol/BidirectionalIndex/"><code>BidirectionalIndex</code></a>,    <a href="../../protocol/ForwardIndex/"><code>ForwardIndex</code></a>    
</div></div>
</div>
<div class="declaration" id="func-distance-to_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-distance-to_">func distance(<wbr>to:)</a>
        
<div class="comment collapse" id="comment-func-distance-to_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">func distance(to other: ReverseRandomAccessIndex&lt;Base&gt;) -&gt; Base.Distance</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/ReverseRandomAccessIndex/"><code>ReverseRandomAccessIndex</code></a>,    <a href="../../protocol/RandomAccessIndex/"><code>RandomAccessIndex</code></a>,    <a href="../../protocol/ReverseIndexProtocol/"><code>ReverseIndexProtocol</code></a>,    <a href="../../protocol/BidirectionalIndex/"><code>BidirectionalIndex</code></a>,    <a href="../../protocol/ForwardIndex/"><code>ForwardIndex</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-predecessor">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-predecessor">func predecessor()</a>
        
<div class="comment collapse" id="comment-func-predecessor"><div class="p">
    <p>Returns the previous consecutive value before <code>self</code>.</p>

<p><strong>Precondition:</strong> The previous value is representable.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func predecessor() -&gt; ReverseRandomAccessIndex&lt;Base&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/BidirectionalIndex/"><code>BidirectionalIndex</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-successor">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-successor">func successor()</a>
        
<div class="comment collapse" id="comment-func-successor"><div class="p">
    <p>Returns the next consecutive value after <code>self</code>.</p>

<p><strong>Precondition:</strong> The next value is representable.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func successor() -&gt; ReverseRandomAccessIndex&lt;Base&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/BidirectionalIndex/"><code>BidirectionalIndex</code></a>    
</div></div>
</div>


